/*
 * XInput1_3-dev - Replacement of xinput library to help with creating
 *                 drivers/debugging application
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 */

#include "stdafx.h"

#include "Utilities.h"

static DWORD g_dwSettings;

HRESULT Utilities::Initialize(void)
{
	g_dwSettings = 5;
	return S_OK;
}

HRESULT Utilities::Close(void)
{
	return S_OK;
}

bool Utilities::IsSettingSet(DWORD dwSetting)
{
	return (dwSetting & g_dwSettings) != dwSetting;
}

HRESULT Utilities::CheckForSettings(DWORD dwSetting, LPVOID lpReserved)
{
	bool bSuccess = true;
	switch ( dwSetting + 0x41110000 )
	{
	case 0:
		return bSuccess;
	case 1:
		if ( lpReserved )
			g_dwSettings |= 1u;
		else
			g_dwSettings &= 0xFFFFFFFEu;
		break;
	case 2:
		if ( lpReserved )
			g_dwSettings |= 2u;
		else
			g_dwSettings &= 0xFFFFFFFDu;
		break;
	case 3:
		if ( lpReserved )
			g_dwSettings |= 4u;
		else
			g_dwSettings &= 0xFFFFFFFBu;
		break;
	default:
		bSuccess = 0;
		break;
	}
	return bSuccess;
}

HRESULT Utilities::SafeCopyToUntrustedBuffer(void *Dst,void const *SafeSrc, size_t Size)
{
	memcpy(Dst, SafeSrc, Size);
	return S_OK;
}

HRESULT Utilities::SafeCopyFromUntrustedBuffer(void *SafeDest,void const *Src, size_t Size)
{
	memcpy(SafeDest, Src, Size);
	return S_OK;
}